import axios from 'axios'
import { createStore } from 'vuex'
export interface stateList{
  list:listType[]
}
export interface listType{
  url:string,
  title:string,
  pic:number,
  id:string
}
export default createStore<stateList>({
  state: {
    list:[]
  },
  getters: {
  },
  mutations: {
    setList:(state,action)=>{
      state.list=action
    },
    getList:(state,action)=>{
      state.list=state.list.filter(v=>v.title.includes(action))
    }
  },
  actions: {
    async listAxios({commit}){
        const resp=await axios.get('/api/list')
        const {list}=resp.data
        commit('setList',list)
    },
    async itemAxios({commit},item){
      if(item!==''){
        commit('getList',item)
      }else{
        const resp=await axios.get('/api/list')
        const {list}=resp.data
        commit('setList',list)
      }
    }
  },
  modules: {
  }
})
